package com.lagou.controller;

import com.alibaba.fastjson.JSON;
import com.lagou.pojo.Student;
import com.lagou.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @ResponseBody
    @RequestMapping("/list")
    public String getList() {
        List<Student> list = studentService.getList(null);
        return JSON.toJSONString(list);
    }

    @ResponseBody
    @RequestMapping("/add")
    public String add(@RequestBody Student student) {
        Student record = studentService.add(student);
        return JSON.toJSONString(record);
    }

}
